package libs;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class Test {
    public static void main(String[] args) throws Exception {
        //1. 导入驱动jar包
        //2.注册驱动
        Class.forName("com.mysql.jdbc.Driver");//mysql5之后的驱动jar包可以省略注册驱动的步骤
        //3.获取数据库连接对象
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/db1?useUnicode=true&characterEncoding=utf8", "root", "x");
//        String url="jdbc:mysql://localhost:3306/soft1901?useUnicode=true&characterEncoding=utf8";
        //4.定义sql语句
//        String sql="insert into Student(StuId,StuName) values('001','小向')";
        String sql="insert into Student(StuId,StuName) values('002','小向')";
         sql="insert into Student(StuId,StuName) values('003','小艾')";
//         sql="insert into Student(StuId,StuName) values('004','小小')";
//         sql="insert into Student(StuId,StuName) values('005','小哈')";
        //5.获取执行sql的对象 Statement
        Statement stmt = conn.createStatement();
        //6.执行sql
        int count = stmt.executeUpdate(sql);
        //7.处理结果
        System.out.println(count);
        //8.释放资源
        stmt.close();
        conn.close();





    }

}
